class Congress {
	private MaxPQMod<State> queue;
	private int states;
	private int seats;
	
	public Congress() {
		System.out.println("Start");
		states = StdIn.readInt();
		queue = new MaxPQMod<State>(states);
		seats = StdIn.readInt()-states;
		System.out.println("Queue initialized");
			
		System.out.println("Adding states...");
		for(int i = 0; i < states; i++){//*2)+1; i++){
			StdIn.readLine(); // Der er en masse mellemrum eller en newline, det tager denne sig af
			String tempS = StdIn.readLine(); //System.out.println(tempS);
			int tempI = StdIn.readInt(); //System.out.println(""+tempI);
			queue.insert(new State(tempS, tempI));
		}
		System.out.println("States added");
		System.out.println("Allocating seats...");
		allocateSeats();
		System.out.println("Seats allocated");
		printResult();
	}
		
	private void allocateSeats() {
		while(seats > 0){
			queue.max().increaseSeats();
			queue.sink(1);
			seats--;
		}
	}
		
	private void printResult() {
		for(State s : queue){
			System.out.println(s.getName() + ": " + s.getSeats());
		}
	}
	
	
	
	
	public static void main(String[] args) {
		Congress c = new Congress();
	}
}